﻿#if UNITY_EDITOR
using System;
/// <summary>
/// CS运算符
/// </summary>
public enum ESF_enCSharpOperator
{
    /// <summary>
    /// 等于
    /// </summary>
    [ESF_AliasTooltip("=")]
    Equals,
    /// <summary>
    /// 大于
    /// </summary>
    [ESF_AliasTooltip(">")]
    Greater,
    /// <summary>
    /// 小于
    /// </summary>
    [ESF_AliasTooltip(">")]
    Less,
    /// <summary>
    /// 不等于
    /// </summary>
    [ESF_AliasTooltip("!=")]
    NotEqual,
    /// <summary>
    /// 大于等于
    /// </summary>
    [ESF_AliasTooltip(">=")]
    GreaterEqual,
    /// <summary>
    /// 小于等于
    /// </summary>
    [ESF_AliasTooltip("<=")]
    LessEqual,
}

/// <summary>
/// CSharp代码特性
/// </summary>
[AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
public class ESF_CSharpCodeAttribute : ESF_AliasTooltipAttribute
{
    /// <summary>
    /// 构造函数
    /// </summary>
    /// <param name="_csTypeOf">typeof类型</param>
    /// <param name="_csType">CS类型</param>
    /// <param name="_csDefault">CS默认值</param>
    /// <param name="_unityType">Unity类型</param>
    /// <param name="_isDeleteJudgeOperator">是否删除判定运算符</param>
    /// <param name="_isDeleteJudgeValue">是否删除判定值</param>
    public ESF_CSharpCodeAttribute(Type _csTypeOf, string _csType, object _csDefault, string _unityType, ESF_enCSharpOperator _isDeleteJudgeOperator, object _isDeleteJudgeValue)
        : base(_csTypeOf.Name)
    {
        csTypeOf = _csTypeOf;
        csType = _csType;
        csDefault = _csDefault;
        unityType = _unityType;
        isDeleteJudgeOperator = _isDeleteJudgeOperator;
        isDeleteJudgeValue = _isDeleteJudgeValue;
    }
    /// <summary>
    /// 是否删除
    /// </summary>
    /// <param name="_value">值</param>
    /// <returns>true:删除,false:不删除</returns>
    public bool isDelete(object _value)
    {
        bool result = false;
        dynamic judgeValue = isDeleteJudgeValue;
        dynamic value = _value;
        switch (isDeleteJudgeOperator)
        {
            case ESF_enCSharpOperator.Equals:
                result |= judgeValue == value;
                break;
            case ESF_enCSharpOperator.Greater:
                result |= judgeValue > value;
                break;
            case ESF_enCSharpOperator.GreaterEqual:
                result |= judgeValue >= value;
                break;
            case ESF_enCSharpOperator.Less:
                result |= judgeValue < value;
                break;
            case ESF_enCSharpOperator.LessEqual:
                result |= judgeValue <= value;
                break;
            case ESF_enCSharpOperator.NotEqual:
                result |= judgeValue != value;
                break;
        }
        return result;
    }

    /// <summary>
    /// typeof类型
    /// </summary>
    public Type csTypeOf { get; private set; }
    /// <summary>
    /// CS类型
    /// </summary>
    public string csType { get; private set; }
    /// <summary>
    /// CS默认值
    /// </summary>
    public object csDefault { get; private set; }
    /// <summary>
    /// Unity类型
    /// </summary>
    public string unityType { get; private set; }
    /// <summary>
    /// 是否删除判定运算符
    /// </summary>
    public ESF_enCSharpOperator isDeleteJudgeOperator { get; private set; }
    /// <summary>
    /// 是否删除判定值
    /// </summary>
    public object isDeleteJudgeValue { get; private set; }
}
#endif